package vip.xiaonuo.modular.cms.config;

import cn.hutool.extra.spring.SpringUtil;
import com.ibeetl.starter.BeetlTemplateCustomize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import vip.xiaonuo.core.context.constant.ConstantContextHolder;
import vip.xiaonuo.core.context.login.LoginContext;
import vip.xiaonuo.core.context.login.LoginContextHolder;
import vip.xiaonuo.modular.cms.service.PublicApiService;
import vip.xiaonuo.modular.cms.service.impl.PublicApiServiceImpl;

/**
 * @ProjectName: snowy_layui_cms
 * @Package: vip.xiaonuo.modular.cms.config
 * @ClassName: BeetlConfig
 * @Author: liubaihan
 * @Description: 模板配置类
 * @Date: 2022/6/27 9:32
 */
@Configuration
public class CMSBeetlConfig {

    /**
     * 自定义配置，注册功能包，前端使用
     *
     * @author xuyuxiang
     * @date 2021/4/8 12:30
     */
    @Bean
    public BeetlTemplateCustomize beetlTemplateCustomize(){
        return groupTemplate -> {
            //登陆上下文
            groupTemplate.registerFunctionPackage("loginContext", new LoginContextHolder().me());
            //常量上下文
            groupTemplate.registerFunctionPackage("constantContext", new ConstantContextHolder());

            // 需要通过SpringUtil获取容器中的对象信息
            // groupTemplate.registerFunctionPackage("temp", TemplateService.class);
            groupTemplate.registerFunctionPackage("cmsService", new PublicServiceHolder().getPublicApiService());
        };
    }

}
